package com.fagertveit.android.game.framework.geom;

public class Collision {
	public static boolean collide(AABB first, AABB second) {
		if(Math.abs(first.pos.x - second.pos.x) > (first.width + second.width))
		{
			return false;
		}
		else if(Math.abs(first.pos.y - second.pos.y) > (first.height + second.height))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	
	public static boolean collide(AABB first, Vector2 second) {
		if(first.pos.x - first.width > second.x || first.pos.x + first.width < second.x) {
			return false;
		}
		else if(first.pos.y - first.height > second.y || first.pos.y + first.height < second.y) {
			return false;
		}
		else {
			return true;
		}
	}
	
	public static boolean collide(Circle first, Circle second) {
		float dist = first.pos.dist(second.pos);
		if(first.radii + second.radii < dist) {
			return true;
		}
		else {
			return false;
		}
	}
	
	public static boolean collide(Circle first, Vector2 second) {
		float dist = first.pos.dist(second);
		if(first.radii < dist) {
			return true;
		}
		else {
			return false;
		}
	}
	
	public static boolean collide(AABB aabb, Circle circle) {
		
		if(Math.abs((aabb.pos.x - circle.pos.x)) > (aabb.width + circle.radii)) {
			return false;
		} else if (Math.abs(aabb.pos.y - circle.pos.y) > (aabb.height + circle.radii)) {
			return false;
		} else {
			if(circle.pos.x < aabb.pos.x - aabb.width) {
				if(circle.pos.y < aabb.pos.y - aabb.height) {
					return collide(circle, new Vector2(aabb.pos.x - aabb.width, aabb.pos.y - aabb.height));
				} else {
					return collide(circle, new Vector2(aabb.pos.x - aabb.width, aabb.pos.y + aabb.height));
				}
			} else {
				if(circle.pos.y < aabb.pos.y - aabb.height) {
					return collide(circle, new Vector2(aabb.pos.x + aabb.width, aabb.pos.y - aabb.height));
				} else {
					return collide(circle, new Vector2(aabb.pos.x + aabb.width, aabb.pos.y + aabb.height));
				}
			}
		}
	}
	
	public static boolean collide(Rectangle first, Vector2 second) {
		if(second.x > first.x && second.x < (first.x + first.width) && second.y > first.y && second.y < (first.y + first.height)) {
			return true;
		} else {
			return false;
		}
	}
}
